/*
 * @Author: silence silence9685@163.com
 * @Date: 2023-07-19 10:02:57
 * @LastEditors: silence silence9685@163.com
 * @LastEditTime: 2023-07-19 14:41:14
 * @FilePath: \ems_neutral_app\lib\pages\Mine\AccountManager\EditNickNamePage.dart
 * @Description: 修改用户昵称
 */
import 'package:ems_neutral_app/base/SilScaffold.dart';
import 'package:ems_neutral_app/common/widgets/cubitWidget/InputView.dart';
import 'package:ems_neutral_app/pages/Mine/Language/SilLocalizations/SilLocalizations.dart';
import 'package:ems_neutral_app/utils/color/ColorUtils.dart';
import 'package:ems_neutral_app/utils/router/ARouter.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';

import '../../../common/Method/CommonMethod.dart';
import '../../../common/widgets/cubitWidget/SubmitBtn.dart';
import 'Controller/AccountManagerController.dart';

class EditNickNamePage extends StatefulWidget {
  const EditNickNamePage({super.key});

  @override
  State<EditNickNamePage> createState() => _EditNickNamePageState();
}

class _EditNickNamePageState extends State<EditNickNamePage> {
  AccountManagerController _accountManagerController =
      Get.put(AccountManagerController());

  String? _nickName;

  @override
  void initState() {
    super.initState();

    _nickName = _accountManagerController.nickName.value;
  }

  @override
  Widget build(BuildContext context) {
    return SilScaffold(
      body: mainWidget(),
    );
  }

  mainWidget() {
    return Container(
      margin: EdgeInsets.only(top: 50.w),
      child: Column(
        children: [
          titleWidget(),
          inputWidget(),
          submitBtnWidget(),
        ],
      ),
    );
  }

  titleWidget() {
    return SilText(
      LangOf(context)?.editNickName?.nickname,
      margin: EdgeInsets.only(top: 50.w),
      fontSize: 19.sp,
      color: ColorUtils.color_font_main,
    );
  }

  inputWidget() {
    return SilEmptyButton(
      useConstrained: true,
      backgroundColor: ColorUtils.color_input_bg,
      margin: EdgeInsets.only(top: 50.w),
      radius: 5.w,
      padding: EdgeInsets.symmetric(vertical: 2.w, horizontal: 10.w),
      child: SilTextField(
          hintText: LangOf(context)?.editNickName?.nicknamePhlace,
          text: _nickName,
          onValid: (valid, value) {
            _nickName = value;
          },
          interface: SilFormattersEmail()),
    );
  }

  submitBtnWidget() {
    return Container(
      alignment: Alignment.center,
      child: SubmitBtn(
        margin: EdgeInsets.only(top: 20.w),
        title: LangOf(context)?.editNickName?.accomplish,
        onTapFunc: () {
          // 隐藏键盘
          globalTextFieldDismiss(context);
          _accountManagerController.requestEditNickName(
              context: context,
              newNickName: _nickName ?? '',
              successHandler: (p0) => ARoute.pop(context));
        },
      ),
    );
  }
}
